function e(e, t, n) {
    return t in e ? Object.defineProperty(e, t, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = n, e;
}

var t, n = require("../../../utils/function.js"), o = require("../../../api.js"), i = getApp(), a = require("../../../siteinfo.js");

Page({
    data: (t = {
        imgcode: "",
        showCode: "",
        sendtxt: "获取验证码",
        phone: null,
        phoneTest: !1,
        verificationcode: null,
        verificationcodeTest: !1
    }, e(t, "sendtxt", "发送验证码"), e(t, "gettingCode", !0), e(t, "password", null), e(t, "passwordTest", !1), 
    e(t, "successCallback", null), e(t, "agreement", {
        stauts: !1,
        image: "http://run.4hl.cn/addons/sd_drviing/core/public/WeChat/driver/icon-34.png"
    }), t),
    onLoad: function() {
        this.getImgCode();
    },
    getImgCode: function() {
        var e = this, t = a.siteroot;
        t = t.replace("/app/index.php", ""), i.request({
            url: o.user.getCatchaKey,
            method: "post",
            data: {},
            success: function(n) {
                e.data.imgCodeKey = n.data.key, e.setData({
                    showCode: t + "/index.php?s=api/user/getCaptcha&key=" + n.data.key + "&_acid=" + a.acid + "&_uniacid=" + a.uniacid + "&time=" + new Date().getTime()
                });
            }
        });
    },
    phoneinput: function(e) {
        this.setData({
            phone: e.detail.value
        });
    },
    imgcodeinput: function(e) {
        this.setData({
            imgcode: e.detail.value
        });
    },
    sendcode: function() {
        var e = this;
        if (console.log(this.data.phone), "" == this.data.phone || !/^1\d{10}$/.test(this.data.phone)) return wx.showToast({
            title: "手机号格式不正确",
            icon: "none"
        }), !1;
        wx.showLoading({}), i.request({
            url: o.user.send_sms + "&phone=" + e.data.phone + "&key=" + e.data.imgCodeKey + "&captcha=" + e.data.imgcode,
            method: "post",
            data: {},
            success: function(t) {
                wx.hideLoading(), 1 == t.code ? (e.setData({
                    gettingCode: !1
                }), n.showToast(t.msg, "none"), e.countDown()) : n.showToast(t.msg, "none");
            }
        });
    },
    countDown: function() {
        var e = this, t = 59, n = setInterval(function() {
            e.setData({
                sendtxt: t + "s"
            }), --t <= 0 && (n = clearInterval(n), e.setData({
                sendtxt: "获取验证码"
            }), e.setData({
                gettingCode: !0
            }), e.data.gettingCode = !0);
        }, 1e3);
    },
    verificationinput: function(e) {
        this.setData({
            verificationcode: e.detail.value
        }), this.verificationTest(e.detail.value);
    },
    verificationTest: function(e) {
        null != e ? this.setData({
            verificationcodeTest: !0
        }) : wx.showToast({
            title: "请输入验证码",
            icon: "none",
            duration: 5e3
        });
    },
    getPhoneLogin: function() {
        var e = this.data.phone, t = this.data.verificationcode;
        if (console.log(e, t), !t) return wx.showToast({
            title: "请输入验证码",
            icon: "none"
        }), !1;
        i.request({
            url: o.user.editPhone,
            method: "post",
            data: {
                phone: e,
                code: t
            },
            success: function(t) {
                if (wx.showToast({
                    title: t.msg,
                    icon: "none"
                }), 1 == t.code) {
                    var n = wx.getStorageSync("user_info");
                    n.phone = e, wx.setStorageSync("user_info", n), setTimeout(function() {
                        wx.navigateBack();
                    }, 1e3);
                }
            }
        }), console.log("修改");
    },
    onShareAppMessage: function() {}
});